package com.xieyingwangluo.yxpart.api;

import com.xieyingwangluo.yxpart.bean.Result;
import com.xieyingwangluo.yxpart.bean.UserEduDTO;
import com.xieyingwangluo.yxpart.entity.UserEducationModel;
import com.xieyingwangluo.yxpart.logic.UserEduLogic;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Api(tags = "教育背景接口")
@Controller
@RequestMapping(value = "/api/v1/user_edu")
public class UserEducationBaseRest extends BaseRest {
    @Autowired
    private UserEduLogic userEduLogic;

    @ApiOperation(value = "添加教育背景", notes = "添加教育背景", produces = "application/json")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "名称", required = true, dataType = "String", paramType = "form"),
            @ApiImplicitParam(name = "major", value = "专业", required = false, dataType = "String", paramType = "form"),
            @ApiImplicitParam(name = "enrollment", value = "入学时间", required = false, dataType = "String", paramType = "form"),
            @ApiImplicitParam(name = "graduation", value = "毕业时间", required = false, dataType = "String", paramType = "form"),
            @ApiImplicitParam(name = "info", value = "在校经历", required = false, dataType = "String", paramType = "form"),
            @ApiImplicitParam(name = "user_id", value = "用户id", required = true, dataType = "String", paramType = "form")})
    @ResponseBody
    @PostMapping(value = "/add")
    public Result add(@RequestHeader(name = "Authorization", defaultValue = "token") String token,
                      UserEduDTO userEduDTO) {
        return userEduLogic.add(userEduDTO);
    }

    @ApiOperation(value = "修改教育背景", notes = "修改教育背景", produces = "application/json")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "noid", value = "教育背景id", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "名称", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "major", value = "专业", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "enrollment", value = "入学时间", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "graduation", value = "毕业时间", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "info", value = "在校经历", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "user_id", value = "用户id", required = false, dataType = "String", paramType = "query")})
    @ResponseBody
    @PutMapping(value = "/upd")
    public Result update(@RequestHeader(name = "Authorization", defaultValue = "token") String token,
                         @RequestParam("noid") String noid,
                         UserEduDTO userEduDTO) {
        return userEduLogic.upd(noid, userEduDTO);
    }
    //显示：用户教育经历编号（noid）

    @ApiOperation(value = "显示教育背景", notes = "显示教育背景", produces = "application/json")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "noid", value = "教育背景id", required = true, dataType = "String", paramType = "query")
    })
    @ResponseBody
    @GetMapping(value = "/selO")
    public Result selO(@RequestHeader(name = "Authorization", defaultValue = "token") String token,
                       @RequestParam("noid") String noid) {
        return userEduLogic.getById(noid);
    }

    @ApiOperation(value = "模糊查询教育背景", notes = "模糊查询教育背景", produces = "application/json")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "名称", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "major", value = "专业", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "enrollment", value = "入学时间", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "graduation", value = "毕业时间", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "info", value = "在校经历", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "user_id", value = "用户id", required = false, dataType = "String", paramType = "query")})
    @ResponseBody
    @PutMapping(value = "/selA")
    public Result selA(@RequestHeader(name = "Authorization", defaultValue = "token") String token,
                       UserEduDTO userEduDTO) {
        return userEduLogic.selA(userEduDTO);
    }
}
